package com.example.springboot.common;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 功能：拦截器的配置
 * 作者：刘涵茹
 * 日期：2024/2/22 10:10
 */

@Configuration//表示配置类
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor()) //配置jwt的拦截器规则
                .addPathPatterns("/**") //'/**'表示拦截所有的请求路径
                .excludePathPatterns("/login","/register");//跳过登录/注册路径,也可以通过自定义注解来跳过路径,和配置拦截器规则配合使用
        super.addInterceptors(registry);
    }

    @Bean//注入对象存入到spring的ioc容器中
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }

}